package day240816;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortStringDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("jack");
        list.add("rose");
        list.add("Ads");
        list.add("tom");
        list.add("fan");
        System.out.println(list);
        Collections.sort(list);
        System.out.println("按照ASCII码："+list);

        List<String> list2 = new ArrayList<>();
        list2.add("成门");
        list2.add("里门四月");
        list2.add("三月初");
        System.out.println(list2);
        Collections.sort(list2,(o1, o2) -> o1.length()-o2.length());
        //Collections.sort(list2,(o1, o2) -> o2.length()-o1.length());//按照元素长度降序
        System.out.println("按照元素长度升序："+list2);

    }
}
